#ifndef INSPECTRECORD_HH_
#define INSPECTRECORD_HH_

#include <boost/shared_ptr.hpp>
#include <lagniappe/Mutex.h>

const uint32_t THRESH = 100;

class InspectRecord
{
  lagniappe::Mutex * mutex;
  std::map<std::string, uint32_t> infractionCount;
  bool blockFlow;
  bool set;
public:
  InspectRecord(lagniappe::Mutex * m) : mutex(m), blockFlow(false), set(false) {}
  void init() {
    mutex->lock();
    infractionCount["BAD"] = 0;
    infractionCount["NAUGHTY"] = 0;
    infractionCount["CREDITCARD"] = 0;
    infractionCount["STEALING"] = 0;
    infractionCount["TRADESECRET"] = 0;
    infractionCount["NIGERIANACCOUNT"] = 0;
    infractionCount["REALLYBAD"] = 0;
    infractionCount["LAKERSFAN"] = 0;
    set = true;
    mutex->notifyAll();
    mutex->unlock();
  }
  uint32_t reportInfraction(std::string offense) {
    mutex->lock();
    while(!set) {
      mutex->wait();
    }
    infractionCount[offense]++;
    if(infractionCount[offense] >= THRESH) {
      blockFlow = true;
    }
    return infractionCount[offense];
  }
  bool blockable() {
    mutex->lock();
    while(!set) {
      mutex->wait();
    }
    bool ret = blockFlow;
    mutex->unlock();
    return ret;
  }
};

typedef boost::shared_ptr<InspectRecord> InspectRecord_p;

#endif // INSPECTRECORD_HH_
